<?php
	try
	{	
		
		require_once('WebService.php');
		require_once('zkErrHandling.php');
		

		write_log("** Inicio Pedido CUIT **");
		$errStr = '-';
		set_error_handler("customError", E_ERROR | E_PARSE | E_USER_ERROR | E_NOTICE | E_WARNING);
		date_default_timezone_set('America/Argentina/Buenos_Aires');


		//$image = ($_SERVER['REQUEST_METHOD'] == "POST")? $_POST['image']: $_GET['image'];
		//$latitude = ($_SERVER['REQUEST_METHOD'] == "POST")? $_POST['lat']: $_GET['lat'];
		//$longitud = ($_SERVER['REQUEST_METHOD'] == "POST")? $_POST['lon']: $_GET['lon'];
		$cuit = ($_SERVER['REQUEST_METHOD'] == "POST")? $_POST['cuit']: $_GET['cuit'];
		$xmlData = ($_SERVER['REQUEST_METHOD'] == "POST")? $_POST['xmldata']: $_GET['xmldata'];

		if ($cuit && !$xmlData)
		{
			// falta el xmlData. Se pide por webserver.
			$xmlData = getXMLData($cuit);
		}
		
		if ($xmlData)
		{
			// escribo para poder verlo.
			$logstr = sprintf("Largo de data recibida: %d", strlen($xmlData));
			write_log($logstr);
			$order= array("\r\n", "\n", "\r", "\t");
			$xmlData = str_replace( $order, '', $xmlData);
			$xmlData = str_replace( "\"", "'", $xmlData);
		}
		else
		{
			$errStr = 'ERROR: mqMain.php ' . 'No encuentra CUIT en la base de datos' . '\n' . 'Contacte mantenimiento';
			//echo $errStr;			
			write_log($errStr);
		}		
	}
	catch (Exception $e)
	{
		//$errStr = '<br><br>ERROR: mqMain.php - <br>' . $e->GetMessage() . '<BR>Contacte mantenimiento<BR>';
		$errStr = 'ERROR: mqMain.php ' . 'No es posible conectarse con el web service' . '\n' . 'Contacte mantenimiento';
		//echo $errStr;
		write_log($errStr . "\n" . $e->GetMessage());	
	}	
	
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ES" lang="ES">
<head>
<title>Ift</title>
<script src="./jquery-ui/jquery-1.9.1.js"></script>
<script type="text/javascript" src="./accordian-src.js"></script>  
<link rel="stylesheet" href="./css/Accordion.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"">
<meta http-equiv="Script-Content-Type" content="text/javascript; charset=utf-8"">
<meta http-equiv="Content-Language" content="ES">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">	
<style type="text/css"></style>
<title>IFT</title>

<script src="mqUtilsAc.js" type="text/javascript"></script>
<script type="text/javascript" >
var lDatos = "<?php echo $xmlData ?>";
var cuit = "<?php echo $cuit ?>";
var errStr = "<?php echo $errStr ?>";
var arrCode;
var colorSel = "#0D8045";		//verde
var colorNSel = "#4162a8";		//azul
var lastChoosed = 0;

function OnPageLoad2(){}

function OnPageLoad()
{
	var grid;			
	var code="";
	
	grid = document.getElementById("zkaccordion");
	if (errStr != '-')
	{
		//alert(errStr);
		//grid = document.getElementById("encabezado");
		code = '<h4>' + errStr + '</h4>';
		grid.innerHTML = code;
		alert(errStr);
		return;
	}
	
	if (lDatos != '') 
	{
		arrCode = doTabsWithXml(lDatos);
		if (typeof arrCode == "string")   // es un error.
			alert("El cuit ingresado no existe: " + cuit);		
			//code = "<p>" + arrCode + "</p>";
		else
		{			
			code = 	"<div id=\"basic-accordian\" ><div style=\"width:175px; float:left\">" ;
			var i;			 
			for (i=0; i< arrCode.length && arrCode[i]; i++)
			{
				code += arrCode[i][0];
			} 
			code += "</div>";
			// ahora los datos.
			code +=	"<div style=\"float:right; width:400px;\">" ;			
			for (i=0; i< arrCode.length && arrCode[i]; i++)
			{
				code += arrCode[i][1];
			} 
			code += "</div>"			
			grid.innerHTML= code; //SAFARI
		} 
	}
	else
	{
		alert("El cuit " + cuit + " no existe en la base");		
		//grid.innerHTML= "<p>  </p>";
	}		
}


function onclick_Datos(i)
{
	var code = arrCode[i][1];
	var grid= document.getElementById("tab_contenido");
	tab[lastChoosed].style.backgroundColor= colorNSel;
	tab[i].style.backgroundColor= colorSel;
	lastChoosed = i;
	grid.innerHTML= code; //SAFARI	
	grid.style.display = 'block';//mostramos el contenido correspondiente
	
}
</script>
</head>
<style type="text/css">
html, body
{
    height: 100%;
    color: black;
    background-color:#F2F5A9;
    style="text-align:center"
}
</style>

<body onLoad="OnPageLoad(); new Accordian('basic-accordian',5,'header_highlight');">  
<!--  <body> <input type="button" id="ALGO" name="ALGO" value="LOAD" onClick="OnPageLoad(); new Accordian('basic-accordian',5,'header_highlight');"> -->
<div id="status"></div>
<div id="zkaccordion"> </div>
</body>
</html>